import { Makers } from './maker';
let _Makers = Makers;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import MakerMock from './mk/mng/card/makerMock';
 * MakerMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/card/maker/listKey').reply(config => {
      let params = config.params;
      let mockMakers = _Makers.filter(maker => {
      	if(params.refuseReason||params.refuseReason==''){ if( maker.refuseReason.indexOf(params.refuseReason)>=0) return true;}
      	if(params.thirdPartyName||params.thirdPartyName==''){ if( maker.thirdPartyName.indexOf(params.thirdPartyName)>=0) return true;}
      	if(params.flowStatus||params.flowStatus==''){ if( maker.flowStatus.indexOf(params.flowStatus)>=0) return true;}
      	if(params.cardId||params.cardId==''){ if( maker.cardId.indexOf(params.cardId)>=0) return true;}
      	if(params.cardPkId||params.cardPkId==''){ if( maker.cardPkId.indexOf(params.cardPkId)>=0) return true;}
      	if(params.deptid||params.deptid==''){ if( maker.deptid.indexOf(params.deptid)>=0) return true;}
      	if(params.createTime||params.createTime==''){ if( maker.createTime.indexOf(params.createTime)>=0) return true;}
      	if(params.createUserid||params.createUserid==''){ if( maker.createUserid.indexOf(params.createUserid)>=0) return true;}
      	if(params.id||params.id==''){ if( maker.id.indexOf(params.id)>=0) return true;}
      	if(params.acctDeptid||params.acctDeptid==''){ if( maker.acctDeptid.indexOf(params.acctDeptid)>=0) return true;}
      	if(params.acctSalesMan||params.acctSalesMan==''){ if( maker.acctSalesMan.indexOf(params.acctSalesMan)>=0) return true;}
      	if(params.acctType||params.acctType==''){ if( maker.acctType.indexOf(params.acctType)>=0) return true;}
      	if(params.percentage||params.percentage==''){ if( maker.percentage.indexOf(params.percentage)>=0) return true;}
      	if(params.branchId||params.branchId==''){ if( maker.branchId.indexOf(params.branchId)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockMakers
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/card/maker/list').reply(config => {
      let params = config.params;
      let mockMakers = _Makers.filter(maker => {
      	var isTrue=false;
      	if(params.refuseReason||params.refuseReason==''){if(maker.refuseReason.indexOf(params.refuseReason)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.thirdPartyName||params.thirdPartyName==''){if(maker.thirdPartyName.indexOf(params.thirdPartyName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.flowStatus||params.flowStatus==''){if(maker.flowStatus.indexOf(params.flowStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.cardId||params.cardId==''){if(maker.cardId.indexOf(params.cardId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.cardPkId||params.cardPkId==''){if(maker.cardPkId.indexOf(params.cardPkId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.deptid||params.deptid==''){if(maker.deptid.indexOf(params.deptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createTime||params.createTime==''){if(maker.createTime.indexOf(params.createTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createUserid||params.createUserid==''){if(maker.createUserid.indexOf(params.createUserid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(maker.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.acctDeptid||params.acctDeptid==''){if(maker.acctDeptid.indexOf(params.acctDeptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.acctSalesMan||params.acctSalesMan==''){if(maker.acctSalesMan.indexOf(params.acctSalesMan)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.acctType||params.acctType==''){if(maker.acctType.indexOf(params.acctType)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.percentage||params.percentage==''){if(maker.percentage.indexOf(params.percentage)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.branchId||params.branchId==''){if(maker.branchId.indexOf(params.branchId)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockMakers
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockMakers.length;
      mockMakers = mockMakers.filter((maker, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockMakers,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/card/maker/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _Makers = _Makers.filter(maker => maker.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/card/maker/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _Makers = _Makers.filter(maker => !params.includes(maker.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/card/maker/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { refuseReason,thirdPartyName,flowStatus,cardId,cardPkId,deptid,createTime,createUserid,id,acctDeptid,acctSalesMan,acctType,percentage,branchId } = params;
      _Makers.some(maker => {
        if (maker.id === id) {
			maker.refuseReason = refuseReason;
			maker.thirdPartyName = thirdPartyName;
			maker.flowStatus = flowStatus;
			maker.cardId = cardId;
			maker.cardPkId = cardPkId;
			maker.deptid = deptid;
			maker.createTime = createTime;
			maker.createUserid = createUserid;
			maker.id = id;
			maker.acctDeptid = acctDeptid;
			maker.acctSalesMan = acctSalesMan;
			maker.acctType = acctType;
			maker.percentage = percentage;
			maker.branchId = branchId
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/card/maker/add').reply(config => {
      var params = JSON.parse( config.data );
      let { refuseReason,thirdPartyName,flowStatus,cardId,cardPkId,deptid,createTime,createUserid,id,acctDeptid,acctSalesMan,acctType,percentage,branchId } = params;
      _Makers.push({
		refuseReason:refuseReason,
		thirdPartyName:thirdPartyName,
		flowStatus:flowStatus,
		cardId:cardId,
		cardPkId:cardPkId,
		deptid:deptid,
		createTime:createTime,
		createUserid:createUserid,
		id:id,
		acctDeptid:acctDeptid,
		acctSalesMan:acctSalesMan,
		acctType:acctType,
		percentage:percentage,
		branchId:branchId
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};